package com.dstz.crm.rest.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dstz.base.api.aop.annotion.CatchErr;
import com.dstz.base.api.query.QueryFilter;
import com.dstz.base.api.query.QueryOP;
import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.base.core.util.StringUtil;
import com.dstz.base.db.model.page.PageResult;
import com.dstz.base.rest.BaseController;
import com.dstz.crm.core.manager.GoodsOrderManager;
import com.dstz.crm.core.model.GoodsOrder;
import com.dstz.sys.util.ContextUtil;
import com.github.pagehelper.Page;



/**
 * 案例 控制器类<br/>
 * @author  aschs
 * </pre>
 */
@RestController
@RequestMapping("/crm/goodsOrder")
public class GoodsOrderController extends BaseController<GoodsOrder>{
	@Resource
	GoodsOrderManager goodsOrderManager;
	
    @RequestMapping("save")
    @Override
    @CatchErr
    public ResultMsg<String> save( @RequestBody GoodsOrder goodsOrder) throws Exception {
       return super.save(goodsOrder);
    }
    
	@Override
	protected String getModelDesc() {
		return "商品订单";
	}
	
	/**
     * 分页列表
     */
    @RequestMapping("listJson")
    public PageResult listJson(HttpServletRequest request, HttpServletResponse response) throws Exception {
        QueryFilter queryFilter = getQueryFilter(request);
        Page<GoodsOrder> pageList = (Page<GoodsOrder>) goodsOrderManager.query(queryFilter);
        return new PageResult(pageList);
    }
    /**
     * 分页列表
     */
    @RequestMapping("myListJson")
    public PageResult myListJson(HttpServletRequest request, HttpServletResponse response) throws Exception {
    	QueryFilter queryFilter = getQueryFilter(request);
    	queryFilter.addFilter("create_by_",ContextUtil.getCurrentUserId(), QueryOP.EQUAL);
    	Page<GoodsOrder> pageList = (Page<GoodsOrder>) goodsOrderManager.query(queryFilter);
    	return new PageResult(pageList);
    }

    /**
     * 批量删除
     */
    @RequestMapping("remove")
    @CatchErr
    public ResultMsg<String> remove(@RequestParam String id) throws Exception {
         String[] aryIds = StringUtil.getStringAryByStr(id);
         goodsOrderManager.removeByIds(aryIds);
         return getSuccessResult(String.format("删除%s成功", getModelDesc()));
    }
    
}
